"""
生成随机彩色头像图片的脚本
"""

import os
import random
from pathlib import Path
from PIL import Image, ImageDraw

def generate_random_color():
    """生成随机颜色"""
    return (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))

def generate_avatar_images(output_dir, count=100):
    """生成头像图片并保存到指定目录"""
    # 确保输出目录存在
    Path(output_dir).mkdir(parents=True, exist_ok=True)
    
    for i in range(count):
        # 创建100x100的图片
        img = Image.new('RGB', (100, 100), color=generate_random_color())
        draw = ImageDraw.Draw(img)
        
        # 在图片上绘制一个圆形
        center = (50, 50)
        radius = 40
        draw.ellipse([center[0] - radius, center[1] - radius, 
                     center[0] + radius, center[1] + radius], 
                    fill=generate_random_color())
        
        # 保存图片
        filename = f"avatar_{i+1:03d}.jpg"
        filepath = os.path.join(output_dir, filename)
        img.save(filepath, 'JPEG')
        
        print(f"已生成头像: {filename}")

def main():
    """主函数"""
    # 设置输出目录
    output_dir = "/Users/kangqing/workspace/doc_service/static/images/avatars"
    
    print("开始生成随机彩色头像...")
    
    # 生成100个头像图片
    generate_avatar_images(output_dir, 100)
    
    print("头像生成完成！")

if __name__ == "__main__":
    main()